import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
export const constantRoutes: Array<RouteRecordRaw> = [
    {//用户管理、部门管理、角色管理、菜单管理、日志管理、数据字典管理、文件管理、图表展示
        path: '/main',
        name: 'main',
        component: ()=>import('../components/HomeView.vue'),
        redirect: 'UserManagement',
        children: [
            {
                name: "UserManagement",
                path: "/UserManagement",
                component: () => import('../components/UserManagement.vue'),
                meta: {
                    title: "用户管理",
                    icon: "Collection"
                },
                children: []
            },
            {
                name: "GoodsManagement",
                path: "/GoodsManagement",
                component: () => import('../components/GoodsManagement.vue'),
                meta: {
                    title: "商品管理",
                    icon: "Operation"
                },
                children: []
            },
            {
                name: "MarketManagement",
                path: "/MarketManagement",
                component: () => import('../components/MarketManagement.vue'),
                meta: {
                    title: "订单管理",
                    icon: "Postcard"
                },
                children: []
            },
            //
            // {
            //     name: "AdministratorsManagement",
            //     path: "/AdministratorsManagement",
            //     component: () => import('../components/UserManagement.vue'),
            //     meta: {
            //         title: "菜单管理",
            //         icon: "Key"
            //     },
            //     children: []
            // }
        ]
    },
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../components/login.vue'),
        children: []
    },
    {
        path: '/:catchAll',
        name: '/404',
        component: () => import('../components/404.vue'),
        children: []
    },

]


export const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    linkActiveClass: 'router-checked',
    routes: constantRoutes
})


// 白名单
//const whiteList = ['/login'] // no redirect whitelist
export const permissionsList = ['/Home', '/login', '/HomePage', '/main'] // no redirect whitelist
router.beforeEach((to, from, next) => {
    next()
  /*  if (getToken() != undefined && permissionsList.indexOf(to.path) !== -1) {
        next()
        //没有token并且是前往login页面
    } else if (getToken() == undefined && whiteList.indexOf(to.path) !== -1) {
        // 未登录,跳转到登陆页面
        next()
    } else {
        next({
            path: '/login'
        })
    }*/
})
export default router
